package org.example;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
class Solution {
    //无进位相乘
    public String multiply(String num1, String num2) {
        int n = num1.length(), m = num2.length();
        int[] nums = new int[n + m - 1];
        for (int i = m - 1; i >= 0; i--){
            for(int j = n - 1; j >= 0; j--){
                // System.out.print(num1.charAt(j) - '0' + " ");
                // System.out.print(num2.charAt(i) - '0' + " ");
                int num = (num1.charAt(j) - '0') *  (num2.charAt(i) - '0');
                nums[j + i] += num;//两数相乘的结果累加到nums数组
            }
        }

        StringBuilder sb = new StringBuilder();
        int t = 0;//用来进位
        for (int i = nums.length - 1; i >= 0; i--) {
            //System.out.print(nums[i] + " ");
            t = t + nums[i];
            sb.append(t % 10);
            t /= 10;
        }
        if(t != 0) sb.append(t);//处理剩余的t
        sb = sb.reverse();
        //去掉前导0
        while(sb.length() > 1 && sb.charAt(0) == '0'){
            sb = sb.deleteCharAt(0);
        }
        return sb.toString();
    }
}